package test.excel;

import java.io.File;
import java.io.InputStream;

/**
 * @Package: com.hx.telegrambot.utils
 * @Description： TODO
 * @Author: Amus Xu
 * @Date: Created in 2022/5/13 2:53 下午
 * @Company: QSQY
 * @Copyright: Copyright (c) 2017
 * @Version: 1.0
 * @Modified By:
 */

public class FileUtil {
    public static InputStream getResourcesFileInputStream(String fileName) {
        return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName);
    }

    public static String getPath() {
        return FileUtil.class.getResource("/").getPath();
    }

    public static File createNewFile(String pathName) {
        File file = new File(getPath() + pathName);
        if (file.exists()) {
            file.delete();
        } else {
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
        }
        return file;
    }

    public static File readFile(String pathName) {
        return new File(getPath() + pathName);
    }

    public static File readUserHomeFile(String pathName) {
        return new File(System.getProperty("user.home") + File.separator + pathName);
    }
}
